<template>
	<view class="main" @touchmove.stop.prevent="() => {}" :style="allStyle()">
  <view class="ptop" style="margin: 10px;">
  	<u-search v-model="query.keyword" @search="getData()" @custom="getData()()"
  		:clearabled="false"></u-search>
  </view>
		<!-- 内容主体 -->
		<view class="content" v-show="projectList.length!=0">
			<view class="content-a" :style="getHeight()">
				<u-list :lowerThreshold="10" @scrolltolower="scrolltolower()" :style="getHei()">
					<u-list-item v-for="(item,index) in projectList" :key="index"
						style="background-color: #FFFFFF;padding: 10px 10px 0px 10px;">
						<view class="u-top"
							style="display: flex;justify-content: space-between;align-items:flex-start;">
							<view class="u-top-left" style="width: 70vw;font-weight: 800;">
								{{ item.xmmc }}
							</view>
							<view class="u-top-right">
								<view class="a" :style="getStyle(item)">
									{{ item.xczt == 0 ? '未巡查' : '已巡查'}}
								</view>
							</view>
						</view>
						<view class="u-middle" style="margin-top: 5px;">
							<view class="m-1" style="display: flex;align-items: center;">
								<u-icon name="account" color="#999" size="14"
									style="margin-top: 1px;margin-right: 2px;"></u-icon>
								<view class="m-1-2" style="color: #999;font-size: 14px;">
									{{ item.xcry }}
								</view>
							</view>
<!-- 							<view class="m-1" style="display: flex;align-items: center;">
								<u-icon name="setting" color="#999" size="14"
									style="margin-top: 1px;margin-right: 2px;"></u-icon>
								<view class="m-1-2" style="color: #999;font-size: 14px;">
									{{ item.jsdw }}
								</view>
							</view> -->
							<view class="m-2" style="display: flex;align-items: center;">
								<u-icon name="clock" color="#999" size="14"
									style="margin-top: 1px;margin-right: 2px;"></u-icon>
								<view class="m-2-2" style="color: #999;font-size: 14px;">
									{{ item.jhkssj == item.jhjssj ? item.jhjssj : `${item.jhkssj}至${item.jhjssj}` }}
								</view>
							</view>
						</view>
						<view class="u-bottom"
							style="margin-top: 5px;display: flex;justify-content: flex-end;align-items: center;">
              <view class="primary-btn" style="display: flex;align-items: center;" v-if="item.xczt == 0">
              	<u-button @click="jumpToXC(item)"
              		style="width: 60px;height: 30px;margin-left: 5px;" text="巡 查"></u-button>
              </view>
							<view class="u-b-public" style="display: flex;align-items: center;">
								<u-button @click="jumpToDetail(item)"
									style="width: 60px;height: 30px;margin-left: 5px;" text="详 情"></u-button>
							</view>
						</view>
						<div style="margin-top: 10px;"><u-line></u-line></div>
					</u-list-item>
				</u-list>
			</view>
		</view>
	</view>
</template>

<script>
	import croods from '@/common/croods-1.3.3.js';
	window.croods = croods;
	window.hydra = require('../../../common/wst_hydra-1.0.0.js');


	import coordtransform from 'coordtransform';
	import {
		proList,
		getDateDic,
		deletePro,
		exportPro,
    getPagingFuturePlan
	} from '@/common/api.js'
	export default {
		onLoad: function(option) {
			this.$nextTick(() => {
				if (option.id != 0) {
					this.user = option.user
					if (option.zd == "true") {
						this.zdPower = true
					}
					if (option.jb == "true") {
						this.jbPower = true
					}
					if (option.sh == "true") {
						this.shPower = true
					}
				}
			})
		},
		onShow() {
			this.columnsa = []
			this.projectList = []
			this.isOk = false
			this.notQx = false
			// this.getDic()
			/* await this.getData() */
      this.getData()
			this.intervalId = setTimeout(() => this.getData(), 60 * 1000);

		},
		onUnload() {
			clearTimeout(this.intervalId);
		},
		data() {
			return {
				user: '',
				zdPower: false,
				jbPower: false,
				shPower: false,
				/* 字典 */
				dic: {
					status: 'Enabled',
					type: 'PROJECT_ZGZT'
				},
				dicList: [],
				/* 头部信息 */
				isXC: false,
				isFK: false,
				/* 选择器 */
				showa: false,
				showb: false,
				taga: '全部',
				tagb: '全部',
				columnsa: [],
				columnsb: [
					[{
						name: '全部',
						value: '',
					}, {
						name: '未反馈',
						value: 0
					}, {
						name: '已反馈',
						value: 1
					}]
				],
				/* 请求 */
				query: {
					pageNum: 1,
					pageSize: 20,
          keyword: '',
          time: ''
				},
				projectList: [],
				isOver: false,
				showd: false,
				deleteid: '',
				oneStatus: false,
				isOk: false,
				intervalId: null,
				notQx: false,
				backShow: false,
				back: {
					id: '',
					thyy: ''
				}
			}
		},
		methods: {
      getStyle(item) {
        return {
          color: item.xczt == 0 ? 'rgb(255, 85, 0)' : 'rgb(83, 194, 29)'
        }
      },
			getDic() {
				getDateDic(this.dic).then(res => {
					this.dicList = res
					let temp = []
					temp.push({
						name: '全部',
						code: ''
					})
					temp = temp.concat(res)
					this.columnsa.push(temp)
					this.getData()
				})
			},
			getData() {
				// proList(this.query).then(res => {
				// 	if ("msgCode" in res && (res.msgCode == "1003" || res.msgCode == "-401")) {
				// 		this.notQx = true
				// 	} else {
				// 		if (res.list.length == 0 && !this.oneStatus) {
				// 			this.isXC = true
				// 			this.oneStatus = true
				// 		}
				// 		if (res.list.length != 0) {
				// 			this.oneStatus = true
				// 			let temp = res.list[0]
				// 			if (temp.zgzt != null) {
				// 				this.isXC = true
				// 			} else {
				// 				this.isFK = true
				// 			}
				// 		}
				// 		if (res.nextPage == 0) {
				// 			this.isOver = true
				// 		}
				// 		const data = res.list.map(item => {
				// 			item.fkztn = ''
				// 			item.zgztn = ''
				// 			if (item.zgzt != null) {
				// 				const dateTemp = this.dicList.find(date => date.code === item.zgzt)
				// 				if (dateTemp) {
				// 					item.zgztn = dateTemp.name
				// 				}
				// 				if (item.zgzt == 4) {
				// 					if (item.fkzt == 1) {
				// 						item.fkztn = '已反馈'
				// 					} else {
				// 						item.fkztn = '未反馈'
				// 					}
				// 				}
				// 			} else {
				// 				if (item.fkzt == 1) {
				// 					item.fkztn = '已反馈'
				// 				} else {
				// 					item.fkztn = '未反馈'
				// 				}
				// 			}
				// 			let dateStr = item.zdsj
				// 			let date = new Date(dateStr)
				// 			let formattedDate = date.getFullYear() + '-' +
				// 				('0' + (date.getMonth() + 1)).slice(-2) + '-' +
				// 				('0' + date.getDate()).slice(-2) + ' ' +
				// 				('0' + date.getHours()).slice(-2) + ':' +
				// 				('0' + date.getMinutes()).slice(-2) + ':' +
				// 				('0' + date.getSeconds()).slice(-2)
				// 			item.zdsjt = formattedDate
				// 			return item
				// 		})
				// 		if (this.projectList.length == 0) {
				// 			this.projectList = data
				// 		} else {
				// 			data.forEach(temp => {
				// 				let ishaving = this.projectList.find(zoo => zoo.id == temp.id)
				// 				if (ishaving) {
				// 					if (ishaving.zgzt != temp.zgzt || (ishaving.zgzt == 4 && temp.zgzt ==
				// 							4 && ishaving.fkzt != temp.fkzt)) {
				// 						let index = this.projectList.findIndex(test => test.id === ishaving
				// 							.id);
				// 						if (index !== -1) {
				// 							this.projectList.splice(index, 1, temp);
				// 						}
				// 					}
				// 				} else {
				// 					this.projectList.push(temp)
				// 				}
				// 			})
				// 		}
				// 	}
				// 	this.isOk = true
				// })
        const date = new Date()
        this.query.time = `${date.getFullYear()}-${(date.getMonth()+1+'').padStart(2,'0')}-${(date.getDate()+'').padStart(2,'0')}`
        getPagingFuturePlan(this.query).then(res => {
          if (res.nextPage == 0) {
            this.isOver = true
          } else {
            this.isOver = false
          }
          this.projectList = res.list
        }).finally(() => {
          clearTimeout(this.intervalId)
          this.intervalId = setTimeout(() => this.getData(), 60 * 1000)
        })
			},
			/* 触底加载 */
			scrolltolower() {
				if (this.isOver) {
					return
				} else {
					this.query.pageNum += 1
					this.getData()
				}
			},
			/* 选择器 */
			getXCPro() {
				this.showa = true
			},
			getStatusXC(e) {
				this.taga = e.value[0].name
				this.query.zgzt = e.value[0].code
				this.projectList = []
				this.getData()
				this.showa = false
			},
			getFKPro() {
				this.showb = true
			},
			getStatusFK(e) {
				this.tagb = e.value[0].name
				this.query.fkzt = e.value[0].value
				this.projectList = []
				this.getData()
				this.showb = false
			},
			/* 删除 */
			deletePro(id) {
				this.showd = true
				this.deleteid = id
			},
			deletePross() {
				deletePro({
					id: this.deleteid
				}).then(res => {
					this.deleteid = ''
					this.showd = false
					this.projectList = []
					this.isOk = false
					this.getData()
				})
			},

			/* 导出 */
			exportPros(id) {
				exportPro({
					id: id
				}).then(res => {
					clearInterval(this.intervalId);
					let addr = res.url
					uni.navigateTo({
						url: `/pages/me/xmxc/pdfpop/index?addr=${addr}`
					})
				})
				/* let addr = 'http://10.10.34.229:8080/wst/static/tabBar/qq.pdf'
				uni.navigateTo({
					url:`/pages/me/xmxc/pdfpop/index?addr=${addr}`
				}) */
			},
			/* 样式 */
			allStyle() {
				let height = uni.getSystemInfoSync().windowHeight
				return {
					'height': height,
					'width': '100%'
				}
			},
			getHeight() {
				let height = uni.getSystemInfoSync().windowHeight - 50
				return {
					'height': height + 'px',
					'width': '100%',
					'display': 'flex',
					'flex-direction': 'column',
					'background-color': '#FAFAFA'
				}
			},
			getHei() {
				let height = uni.getSystemInfoSync().windowHeight - 50
				return {
					'height': height + 'px'
				}
			},
			getXCStyle(xc) {
				if (xc == '已审核') {
					return {
						'font-size': '14px',
						'color': '#53c21d'
					}
				} else {
					return {
						'font-size': '14px',
						'color': '#FF5500'
					}
				}
			},
			getFKStyle(fk) {
				if (fk == '已反馈') {
					return {
						'font-size': '14px',
						'color': '#53c21d'
					}
				} else {
					return {
						'font-size': '14px',
						'color': '#FF5500'
					}
				}
			},
			/* 定时刷新 */
			getNewData() {
				this.query.pageNum = 1
				proList(this.query).then(res => {
					if (res.nextPage == 0) {
						this.isOver = true
					}
					const data = res.list.map(item => {
						item.fkztn = ''
						item.zgztn = ''
						if (item.zgzt != null) {
							const dateTemp = this.dicList.find(date => date.code === item.zgzt)
							if (dateTemp) {
								item.zgztn = dateTemp.name
							}
							if (item.zgzt == 4) {
								if (item.fkzt == 1) {
									item.fkztn = '已反馈'
								} else {
									item.fkztn = '未反馈'
								}
							}
						} else {
							if (item.fkzt == 1) {
								item.fkztn = '已反馈'
							} else {
								item.fkztn = '未反馈'
							}
						}
						let dateStr = item.zdsj
						let date = new Date(dateStr)
						let formattedDate = date.getFullYear() + '-' +
							('0' + (date.getMonth() + 1)).slice(-2) + '-' +
							('0' + date.getDate()).slice(-2) + ' ' +
							('0' + date.getHours()).slice(-2) + ':' +
							('0' + date.getMinutes()).slice(-2) + ':' +
							('0' + date.getSeconds()).slice(-2)
						item.zdsjt = formattedDate
						return item
					})
					this.projectList = data
				})
			},
			/* 跳转 */
			jump(title, id) {
				clearInterval(this.intervalId);
				uni.navigateTo({
					url: `/pages/me/xmxc/xjxc/index?id=${id}&title=${title}`
				})
			},
      jumpToXC(item) {
        clearTimeout(this.intervalId)
        uni.navigateTo({
          url: `/pages/me/xcrz/index?id=${item.id}&xmid=${item.xmid}&xmmc=${item.xmmc}`
        })
      },
			jumpToDetail(item) {
				clearTimeout(this.intervalId);
				uni.navigateTo({
					url: `/pages/me/xmxcjh/xmxcjhxq/index?id=${item.id}&title=${item.xmmc}&xmid=${item.xmid}&planXmRelId=${item.planXmRelId}`
				})
			},
			goTo(title, id, zgzt) {
				clearInterval(this.intervalId);
				uni.navigateTo({
					url: `/pages/me/xmxc/xcsc/index?id=${id}&title=${title}&zgzt=${zgzt}`
				})
			},
			editPro(id, zgzt) {
				clearInterval(this.intervalId);
				uni.navigateTo({
					url: `/pages/me/xmxc/xcbj/index?id=${id}&zgzt=${zgzt}`
				})
			},
			goToFK(id) {
				clearInterval(this.intervalId);
				uni.navigateTo({
					url: `/pages/me/xmxc/fkxq/index?id=${id}`
				})
			}
		},
		async mounted() {

		}
	}
</script>

<style scoped>
  .primary-btn /deep/ .u-button--info{
    color: white;
    background-color: rgb(255, 85, 0);
    border-color: rgb(255, 85, 0);
    border-width: 1px;
    border-style: solid;
  }
</style>